<?php

namespace App\Exports;

use App\Models\Asset;
use App\Models\AssetStock;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;

class AssetStockInputTemplateExport implements WithColumnFormatting, FromCollection, WithMapping, WithHeadings
{
    /**
    * @return \Illuminate\Support\Collection
    */
    public function collection()
    {
        $simpleAsset = new AssetStock([
            "name" => "必填",
            "init_quantity" => '必填',
            "marking_price_per_unit" => '必填',
            "bid_price_per_unit" => '必填',
            "category_id" => '必填',
            "sub_category_id" => '必填',
            "brand_id" => '必填',
            "status_id" => '必填',
            "affiliation_id" => '必填',
            "keeper_id" => '必填'
        ]);
        return collect([$simpleAsset]);
    }

    /**
     * @return array
     */
    public function columnFormats(): array
    {
        // TODO: Implement columnFormats() method.
        return [];
    }

    /**
     * @return array
     */
    public function headings(): array
    {
        return [
            '名称',
            '物品编码',
            '单位/市场价',
            '单位/购入价',
            '初始数量',
            '有效数量',
            '借出数量',
            '总数',
            '主类',
            '副类',
            '品牌',
            '归属',
            '保管人',
            '供应商',
            '仓库',
        ];
    }

    /**
     * @param mixed $row
     *
     * @return array
     */
    public function map($row): array
    {
//        $row = new AssetStock();
        return [
            $row->name,
            $row->product_model_number,
            $row->marking_price_per_unit,
            $row->bid_price_per_unit,
            $row->init_quantity,
            $row->available_quantity,
            $row->checkout_quantity,
            $row->total_quantity,
            $row->category_id,
            $row->sub_category_id,
            $row->brand_id,
            $row->affiliation_id,
            $row->keeper_id,
            $row->vendor_id,
            $row->location_id
        ];
    }
}
